<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>assignObj</title>
</head>

<body>
    <div>打开控制台查看结果</div>
    <script>
        const assignObj = (target, ...args) => {
            if (target === null) {
                return;
            }
            const _ = Object(target);
            args.forEach(item => {
                if (item) {
                    for (let key in item) {
                        if (Object.prototype.hasOwnProperty.call(item, key)) {
                            _[key] = item[key];
                        }
                    }
                }
            });
            return _;
        };
        console.log(assignObj({}, { a: 1, b: 2 }))
        console.log(assignObj({ a: 3, c: 1 }, { a: 4, b: 2 }))
    </script>
</body>

</html>